<?php
namespace app\tadmin\controller;
use app\tadmin\model\Setting as SettingModel;
/**
 * 
 * 后台设置
 */
class Setting extends Controller{

    public function index(){
        return $this->updateEvent('sys');
    }


    /**
     * 更新设置事件
     * @param $key
     * @return array|mixed
     * @throws \think\exception\DbException
     */
    private function updateEvent($key)
    {
        if (!$this->request->isAjax()) {
            $values = SettingModel::getItem($key);
            //print_r($values);
            return $this->fetch($key, compact('values'));
        }
        $model = new SettingModel;
        if ($model->edit($key, $this->postData($key))) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError('更新失败');
    }
}